package com.xiaoba.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: Gd
 * @package: com.xiaoba.product.config
 * @Project: XiaoBa
 * @Name: ThreadPoolExcuterConfig
 * @Date: 2024/6/5 16:30
 */
@Configuration
@Component
public class ThreadPoolExcuterConfig {

    @Bean
    public ThreadPoolExecutor itemInfoThreadPool(ItemInfoThreadPoolProperties itemInfoThreadPoolProperties){

        return new ThreadPoolExecutor(
                itemInfoThreadPoolProperties.getCoreSize(),
                itemInfoThreadPoolProperties.getMaxSize(),
                itemInfoThreadPoolProperties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(2000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    @Bean
    public ThreadPoolExecutor orderInfoThreadPool(){

        return new ThreadPoolExecutor(
                1,
                12,
                20,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(2000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
